import json

from pygments import highlight
from pygments.formatters.terminal import TerminalFormatter
from pygments.lexers.data import JsonLexer

data = {"key": "value", "nums": [1, 2, 3]}
json_str = json.dumps(data, indent=4)  # 先格式化

print(highlight(json_str, JsonLexer(), TerminalFormatter()))
